package cn.usian.basicInformation.sensitivewords.config;

import cn.usian.basicInformation.sensitivewords.service.ISensitiveWordsService;
import cn.usian.config.ResultException;
import cn.usian.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
@Slf4j
public class SensitiveWords {
    @Autowired
    private ISensitiveWordsService sensitiveWordsServicel;

    public Result sensitiveWords(String sensitiveWords) {
        Set<String> set = sensitiveWordsServicel.sensitiveWordFiltering(sensitiveWords);
        for (String string : set) {
            System.out.println(string);
        }
        if(set.size()>0){
            //logAndThrow("存在敏感词："+set);
            return Result.error("存在敏感词："+set);
        }
        return Result.ok();
    }

    private void logAndThrow(String message) {
        log.error(message);
        throw new ResultException(message);
    }
}
